package JVM;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

public class ReferenceQueueDemo {

    public static void main(String[] args) {
        Object o1 = new Object();
        ReferenceQueue<Object> referenceQueue = new ReferenceQueue();
        WeakReference<Object> reference = new WeakReference(o1, referenceQueue);

        o1 = null;

        System.out.println(o1);
        System.out.println(reference.get());
        System.out.println(referenceQueue.poll());

        System.out.println("============");

        System.gc();
        System.out.println(o1);
        System.out.println(reference.get());
        System.out.println(referenceQueue.poll());


    }
}
